/**
 * 
 */
package org.mspring.mlog.service.impl;

import java.util.List;

import org.mspring.mlog.dao.LinkDao;
import org.mspring.mlog.entity.Link;
import org.mspring.mlog.service.LinkService;
import org.mspring.platform.core.AbstractServiceSupport;
import org.mspring.platform.persistence.query.QueryCriterion;
import org.mspring.platform.persistence.support.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author fairchildy
 * @since 2012-7-30
 * @Description
 * @TODO
 */
@Service
@Transactional
public class LinkServiceImpl extends AbstractServiceSupport implements LinkService {

	@Autowired
	private LinkDao linkDao;
    /*
     * (non-Javadoc)
     * 
     * @see org.mspring.mlog.service.LinkService#findLinks(org.mspring.platform.
     * persistence.support.Page, java.lang.String)
     */
    @Override
    public Page<Link> findLinks(Page<Link> linkPage, String queryString) {
        // TODO Auto-generated method stub
    	return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.mspring.mlog.service.LinkService#findLinks(org.mspring.platform.
     * persistence.support.Page, java.lang.String, java.lang.Object[])
     */
    @Override
    public Page<Link> findLinks(Page<Link> linkPage, String queryString, Object... params) {
        // TODO Auto-generated method stub
    	return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.mspring.mlog.service.LinkService#findVisableLinks()
     */
    @Override
    public List<Link> findVisableLinks() {
        // TODO Auto-generated method stub
    	return null;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.mspring.mlog.service.LinkService#deleteLinks(java.lang.Long[])
     */
    @Override
    public void deleteLinks(Long... idArray) {
        // TODO Auto-generated method stub
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.mspring.mlog.service.LinkService#getLinkById(java.lang.Long)
     */
    @Override
    public Link getLinkById(Long id) {
        // TODO Auto-generated method stub
    	return null;
    }

    /* (non-Javadoc)
     * @see org.mspring.mlog.service.LinkService#findLinks(org.mspring.platform.persistence.support.Page, org.mspring.platform.persistence.query.QueryCriterion)
     */
    @Override
    public Page<Link> findLinks(Page<Link> linkPage, QueryCriterion queryCriterion) {
        // TODO Auto-generated method stub
    	return null;
    }

	@Override
	public Page<Link> findLinks(Page<Link> linkPage) {
		
		int pageFrom = (linkPage.getPageNo() - 1)* linkPage.getPageSize();
		int pageCount = 0;
		Link link = new Link();
		link.setPageFrom(pageFrom);
		link.setuSER_ID(linkPage.getuSER_ID());
		if (linkPage.getTotalCount() < 0) {
			pageCount = linkDao.getPageCount(link);
			linkPage.setTotalCount(pageCount);
			linkPage.setTotalPages(pageCount/linkPage.getPageSize() + 1);
		}
		
		List<Link> list = linkDao.getPage(link);
		linkPage.setResult(list);
		
		return linkPage;
	}

	@Override
	public Link getLinkById(Link link) {
		Link reslut = linkDao.getLinkById(link);
		return reslut;
	}
    /*
     * (non-Javadoc)
     * 
     * @see
     * org.mspring.mlog.service.LinkService#updateLink(org.mspring.mlog.entity
     * .Link)
     */
    @Override
    public void updateLink(Link link) {
    	linkDao.updateLink(link);
    }
    
    /*
     * (non-Javadoc)
     * 
     * @see
     * org.mspring.mlog.service.LinkService#createLink(org.mspring.mlog.entity
     * .Link)
     */
    @Override
    public void createLink(Link link) {
    	linkDao.createLink(link);
    }

	@Override
	public void deleteLinks(Link link) {
		linkDao.deleteLinks(link);
		
	}
}
